<?php
namespace Admin\Controller;
use Think\Controller;
class CategoryController extends CommonController{
	//显示首页
	public function index(){
		$model=D('category');
		$info=$model->index();
		$this->assign('category',$info);
		$this->display();
	}

	//显示添加界面面
	public function add(){
		$this->display();
	}
	//添加类别
   public function addDo(){
   	//echo  "到这里了";
   	if(!IS_POST){
   		$this->error('非法提交数据');
   		exit;
   	}else{
   		$model=D('category');
   		if(!$model->create()){
   			$this->error($model->getError());
   		}else{
            $info=$model->addDo();
            if($info!==false){
            	$this->success('添加成功',U('Category/index'));
            }else{
            	$this->error('添加失败');
            }
   		}

   	}

   }
   //显示编辑
   public function edit(){
   	$model=D('category');
   	$info=$model->edit();
   	$this->assign('edit',$info);
   	$this->display();
   }
   //编辑
   public function editDo(){
   	if(!IS_POST){
   		$this->error('非法提交数据');
   		exit;
   	}else{
   		$model=D('category');
   		if(!$model->create()){
   			$this->error($model->getError());
   			exit;
   		}else{
   			$info=$model->editDo();
   			if($info>=0){
   				$this->success('添加成功',U('Category/edit'));
   			}else{
   				$this->error('添加失败');
   			}
   		}
   	}
   }
   //删除操作
 public function del(){
      $model = D('Category');
      $info = $model -> del();
      if(0 !== $info){
         $this -> redirect('Category/index');
      }else{
         echo "<script>alert('有子分类不能删除！');window.history.back(-1); </script>";   
      }
   }   }

